/**
 */
package org.xtext.context.aware.eventX.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import org.xtext.context.aware.eventX.Date;
import org.xtext.context.aware.eventX.EventXPackage;
import org.xtext.context.aware.eventX.TimeTable;
import org.xtext.context.aware.eventX.WeekDayTime;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Time Table</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.xtext.context.aware.eventX.impl.TimeTableImpl#getDateFrom <em>Date From</em>}</li>
 *   <li>{@link org.xtext.context.aware.eventX.impl.TimeTableImpl#getDateTo <em>Date To</em>}</li>
 *   <li>{@link org.xtext.context.aware.eventX.impl.TimeTableImpl#getWeekdays <em>Weekdays</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class TimeTableImpl extends ElementImpl implements TimeTable
{
  /**
   * The cached value of the '{@link #getDateFrom() <em>Date From</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getDateFrom()
   * @generated
   * @ordered
   */
  protected Date dateFrom;

  /**
   * The cached value of the '{@link #getDateTo() <em>Date To</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getDateTo()
   * @generated
   * @ordered
   */
  protected Date dateTo;

  /**
   * The cached value of the '{@link #getWeekdays() <em>Weekdays</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getWeekdays()
   * @generated
   * @ordered
   */
  protected EList<WeekDayTime> weekdays;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected TimeTableImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return EventXPackage.Literals.TIME_TABLE;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Date getDateFrom()
  {
    return dateFrom;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetDateFrom(Date newDateFrom, NotificationChain msgs)
  {
    Date oldDateFrom = dateFrom;
    dateFrom = newDateFrom;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EventXPackage.TIME_TABLE__DATE_FROM, oldDateFrom, newDateFrom);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setDateFrom(Date newDateFrom)
  {
    if (newDateFrom != dateFrom)
    {
      NotificationChain msgs = null;
      if (dateFrom != null)
        msgs = ((InternalEObject)dateFrom).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - EventXPackage.TIME_TABLE__DATE_FROM, null, msgs);
      if (newDateFrom != null)
        msgs = ((InternalEObject)newDateFrom).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - EventXPackage.TIME_TABLE__DATE_FROM, null, msgs);
      msgs = basicSetDateFrom(newDateFrom, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EventXPackage.TIME_TABLE__DATE_FROM, newDateFrom, newDateFrom));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Date getDateTo()
  {
    return dateTo;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetDateTo(Date newDateTo, NotificationChain msgs)
  {
    Date oldDateTo = dateTo;
    dateTo = newDateTo;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EventXPackage.TIME_TABLE__DATE_TO, oldDateTo, newDateTo);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setDateTo(Date newDateTo)
  {
    if (newDateTo != dateTo)
    {
      NotificationChain msgs = null;
      if (dateTo != null)
        msgs = ((InternalEObject)dateTo).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - EventXPackage.TIME_TABLE__DATE_TO, null, msgs);
      if (newDateTo != null)
        msgs = ((InternalEObject)newDateTo).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - EventXPackage.TIME_TABLE__DATE_TO, null, msgs);
      msgs = basicSetDateTo(newDateTo, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EventXPackage.TIME_TABLE__DATE_TO, newDateTo, newDateTo));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<WeekDayTime> getWeekdays()
  {
    if (weekdays == null)
    {
      weekdays = new EObjectContainmentEList<WeekDayTime>(WeekDayTime.class, this, EventXPackage.TIME_TABLE__WEEKDAYS);
    }
    return weekdays;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case EventXPackage.TIME_TABLE__DATE_FROM:
        return basicSetDateFrom(null, msgs);
      case EventXPackage.TIME_TABLE__DATE_TO:
        return basicSetDateTo(null, msgs);
      case EventXPackage.TIME_TABLE__WEEKDAYS:
        return ((InternalEList<?>)getWeekdays()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case EventXPackage.TIME_TABLE__DATE_FROM:
        return getDateFrom();
      case EventXPackage.TIME_TABLE__DATE_TO:
        return getDateTo();
      case EventXPackage.TIME_TABLE__WEEKDAYS:
        return getWeekdays();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case EventXPackage.TIME_TABLE__DATE_FROM:
        setDateFrom((Date)newValue);
        return;
      case EventXPackage.TIME_TABLE__DATE_TO:
        setDateTo((Date)newValue);
        return;
      case EventXPackage.TIME_TABLE__WEEKDAYS:
        getWeekdays().clear();
        getWeekdays().addAll((Collection<? extends WeekDayTime>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case EventXPackage.TIME_TABLE__DATE_FROM:
        setDateFrom((Date)null);
        return;
      case EventXPackage.TIME_TABLE__DATE_TO:
        setDateTo((Date)null);
        return;
      case EventXPackage.TIME_TABLE__WEEKDAYS:
        getWeekdays().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case EventXPackage.TIME_TABLE__DATE_FROM:
        return dateFrom != null;
      case EventXPackage.TIME_TABLE__DATE_TO:
        return dateTo != null;
      case EventXPackage.TIME_TABLE__WEEKDAYS:
        return weekdays != null && !weekdays.isEmpty();
    }
    return super.eIsSet(featureID);
  }

} //TimeTableImpl
